<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>运行时配置</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongo.installation.html">安装</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongo.manual.html">手册</a></div>
 <div class="up"><a href="extname.setup.html">安装／配置</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="mongo.configuration" class="section">
 <h2 class="title">运行时配置</h2>
 <p class="simpara">
这些函数的行为受 <var class="filename">php.ini</var> 中的设置影响。
</p>
 <p class="para">
  <table class="doctable table">
   <caption><strong>Mongo 配置选项</strong></caption>
   
    <thead>
     <tr>
      <th>名字</th>
      <th>默认</th>
      <th>可修改范围</th>
      <th>更新日志</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td><a href="mongo.configuration.html#ini.mongo.allow-empty-keys" class="link">mongo.allow_empty_keys</a></td>
      <td>0</td>
      <td>PHP_INI_ALL</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="mongo.configuration.html#ini.mongo.allow-persistent" class="link">mongo.allow_persistent</a></td>
      <td>1</td>
      <td>PHP_INI_ALL</td>
      <td>Removed in 1.2.0</td>
     </tr>

     <tr>
      <td><a href="mongo.configuration.html#ini.mongo.chunk-size" class="link">mongo.chunk_size</a></td>
      <td>262144</td>
      <td>PHP_INI_ALL</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="mongo.configuration.html#ini.mongo.cmd" class="link">mongo.cmd</a></td>
      <td>&quot;$&quot;</td>
      <td>PHP_INI_ALL</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="mongo.configuration.html#ini.mongo.default-host" class="link">mongo.default_host</a></td>
      <td>&quot;localhost&quot;</td>
      <td>PHP_INI_ALL</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="mongo.configuration.html#ini.mongo.default-port" class="link">mongo.default_port</a></td>
      <td>27017</td>
      <td>PHP_INI_ALL</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="mongo.configuration.html#ini.mongo.is-master-interval" class="link">mongo.is_master_interval</a></td>
      <td>15</td>
      <td>PHP_INI_ALL</td>
      <td>Added in 1.2.10, before 1.3.0 the default value was 60.</td>
     </tr>

     <tr>
      <td><a href="mongo.configuration.html#ini.mongo.long-as-object" class="link">mongo.long_as_object</a></td>
      <td>0</td>
      <td>PHP_INI_ALL</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="mongo.configuration.html#ini.mongo.native-long" class="link">mongo.native_long</a></td>
      <td>0<a href="mongo.configuration.html#ini.mongo.native-long" class="link">*</a></td>
      <td>PHP_INI_ALL</td>
      <td class="empty">&nbsp;</td>
     </tr>

     <tr>
      <td><a href="mongo.configuration.html#ini.mongo.ping-interval" class="link">mongo.ping_interval</a></td>
      <td>5</td>
      <td>PHP_INI_ALL</td>
      <td>Added in 1.2.10</td>
     </tr>

     <tr>
      <td><a href="mongo.configuration.html#ini.mongo.utf8" class="link">mongo.utf8</a></td>
      <td>1</td>
      <td>PHP_INI_ALL</td>
      <td class="empty">&nbsp;</td>
     </tr>

    </tbody>
   
  </table>

  有关 PHP_INI_* 样式的更多详情与定义，见 <a href="configuration.changes.modes.html" class="xref">配置可被设定范围</a>。
 </p>

 <p class="para">这是配置指令的简短说明。</p>

 <p class="para">
  <dl>

   
    <dt id="ini.mongo.allow-empty-keys">
     <em><code class="parameter">mongo.allow_empty_keys</code></em>
     <span class="type"><a href="language.types.integer.html" class="type int">int</a></span>
    </dt>

    <dd>

     <p class="para">
      Added in version 1.0.11.
     </p>
     <p class="para">
      If empty strings (&quot;&quot;) should be allowed as key names.  By default, the 
      driver will throw an exception if you attempt to pass the empty string as
      a key to the database.  It is extremely easy to do this inavertently by 
      using double quotes with $-operators, so it is recommended that you leave
      this setting as default.  However, if you need to save keys that are empty
      strings, you can set this option to true and the driver will allow you to
      pass empty strings to the database.
     </p>
    </dd>

     

   
    <dt id="ini.mongo.allow-persistent">
     <em><code class="parameter">mongo.allow_persistent</code></em>
     <span class="type"><a href="language.types.integer.html" class="type int">int</a></span>
    </dt>

    <dd>

     <p class="para">
      If persistent connections are allowed. (Removed in 1.2.0 - all
      connections are now persistent).
     </p>
    </dd>

     

   
    <dt id="ini.mongo.chunk-size">
     <em><code class="parameter">mongo.chunk_size</code></em>
     <span class="type"><a href="language.types.integer.html" class="type int">int</a></span>
    </dt>

    <dd>

     <p class="para">
      The number of bytes-per-chunk.  Used in divvying up GridFS files. This 
      number must be at least 100 less than 4 megabytes (max: 4194204) and it is
      recommended that it be less than that.
     </p>
    </dd>

     

   
    <dt id="ini.mongo.cmd">
     <em><code class="parameter">mongo.cmd</code></em>
     <span class="type"><a href="language.types.string.html" class="type string">string</a></span>
    </dt>

    <dd>

     <p class="para">
      A character to be used in place of $ in modifiers and comparisons.
     </p>
     <p class="para">
      As it is easy to forget to escape the &quot;$&quot;, you can also choose your own
      special character to use instead of &#039;$&#039;.  Choose a character that will not
      occur in your key names, e.g. &quot;:&quot;:
     </p>
     <div class="example-contents">
<div class="cdata"><pre>
mongo.cmd = &quot;:&quot;
</pre></div>
     </div>

     <p class="para">
      Then, to do a comparison, for example:
     </p>
     <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$query&nbsp;</span><span style="color: #007700">=&nbsp;array(&nbsp;</span><span style="color: #DD0000">"i"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(&nbsp;</span><span style="color: #DD0000">":gt"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">20</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">":lte"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">30&nbsp;</span><span style="color: #007700">)&nbsp;);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

     <p class="para">
      You can also change it in your code using 
      <em>ini_set(&quot;mongo.cmd&quot;, &quot;:&quot;)</em>.  Of course, you can also 
      just use single quotes or backslash-escape the $.
     </p>
    </dd>

     

   
    <dt id="ini.mongo.default-host">
     <em><code class="parameter">mongo.default_host</code></em>
     <span class="type"><a href="language.types.string.html" class="type string">string</a></span>
    </dt>

    <dd>

     <p class="para">
      Default hostname when nothing is passed to the constructor.
     </p>
    </dd>

   

   
    <dt id="ini.mongo.default-port">
     <em><code class="parameter">mongo.default_port</code></em>
     <span class="type"><a href="language.types.string.html" class="type string">string</a></span>
    </dt>

    <dd>

     <p class="para">
      The default TCP port number to use when connecting to the database server 
      if no other port is specified. The database&#039;s default is 
      <em>27017</em>.
     </p>
    </dd>

   
  
   
    <dt id="ini.mongo.is-master-interval">
     <em><code class="parameter">mongo.is_master_interval</code></em>
     <span class="type"><a href="language.types.integer.html" class="type int">int</a></span>
    </dt>

    <dd>

     <p class="para">
      Added in version 1.2.10.
     </p>
     <p class="para">
      For replicaset connections: The minimum interval with which the driver
      will send &quot;isMaster&quot; requests to the MongoDB server. If the value is lower,
      there will be more requests, but the driver finds faster whether the
      topology of the replicaset has been changed.
     </p>
    </dd>

     

   
    <dt id="ini.mongo.long-as-object">
     <em><code class="parameter">mongo.long_as_object</code></em>
     <span class="type"><a href="language.types.integer.html" class="type int">int</a></span>
    </dt>

    <dd>

     <p class="para">
      Return a BSON_LONG as an instance of <a href="class.mongoint64.html" class="classname">MongoInt64</a>
      (instead of a primitive type).
     </p>
    </dd>

   

   
    <dt id="ini.mongo.native-long">
     <em><code class="parameter">mongo.native_long</code></em>
     <span class="type"><a href="language.types.integer.html" class="type int">int</a></span>
    </dt>

    <dd>

     <p class="para">
      <em class="emphasis">
       The default behavior for this will be changed to <strong><code>TRUE</code></strong> in 2.0.0, so make
       sure to set this variable to the value you want (probably <strong><code>TRUE</code></strong>) so that 
       the driver&#039;s behavior doesn&#039;t suddenly change when you upgrade.
      </em>
     </p>
     <p class="para">
      On 64-bit platforms, the <em>mongo.native_long</em> setting 
      allows for 64-bit integers to be stored in MongoDB. If it is not set, only
      32-bits of the integer will be saved.  The MongoDB data type that is used 
      in this case is the BSON LONG, instead of the BSON INT that is used if 
      this setting is turned off. 
     </p>
     <p class="para">
      The setting also changes the way how BSON LONGs behave when they are read 
      back from MongoDB. Without <em>mongo.native_long</em> enabled, 
      the driver would convert every BSON LONG to a PHP double which can result 
      in a loss of precision. 
     </p>
     <p class="para">
      On 32-bit platforms, the <em>mongo.native_log</em> setting 
      changes nothing for storing integers in MongoDB: the integer is stored 
      as a BSON INT as before. However, when the setting is enabled and a 
      BSON LONG is read from MongoDB a 
      <a href="class.mongocursorexception.html" class="classname">MongoCursorException</a> is thrown alerting you that 
      the data could not be read back without losing precision.
     </p>
     <p class="para">
      On 32-bit systems especially, it is recommended that you combine this with
      enabling <em>mongo.long_as_object</em>.
     </p>
    </dd>

   

   
    <dt id="ini.mongo.ping-interval">
     <em><code class="parameter">mongo.ping_interval</code></em>
     <span class="type"><a href="language.types.integer.html" class="type int">int</a></span>
    </dt>

    <dd>

     <p class="para">
      Added in version 1.2.10.
     </p>
     <p class="para">
      For replicaset connections: The minimum interval with which the driver
      will send &quot;ping&quot; requests to the MongoDB server. If the value is lower,
      there will be more pings, but the driver finds faster whether a node is
      no longer reachable from the replicaset.
     </p>
    </dd>

     

   
    <dt id="ini.mongo.utf8">
     <em><code class="parameter">mongo.utf8</code></em>
     <span class="type"><a href="language.types.integer.html" class="type int">int</a></span>
    </dt>

    <dd>

     <p class="para">
      If an exception should be thrown for non-UTF8 strings.  Until version 
      1.0.4, the PHP driver would ignore non-UTF8 strings, even though you&#039;re
      not supposed to insert them.  As of 1.0.4, the driver throws a 
      <a href="class.mongoexception.html" class="classname">MongoException</a>.  To ease the transition for 
      applications that insert non-UTF8 strings, you can turn this option off to
      emulate the old, non-exception-throwning behavior.  This option will be
      eliminated and exceptions always thrown for non-UTF8 strings starting with
      version 1.1.0.
     </p>
    </dd>

     

  </dl>

 </p>
</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongo.installation.html">安装</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongo.manual.html">手册</a></div>
 <div class="up"><a href="extname.setup.html">安装／配置</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
